﻿@model SrBBSPro.Entities.Bug
@{
    ViewBag.Title = "项目障害详细";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    var IsAdmin = Convert.ToBoolean(Session["IsAdmin"]);
}
<div class="main layui-clear">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>障害 @Model.No  @Model.StatusName</legend>
    </fieldset>
    <div class="fly-tab user-tab">
        <span id="tabs">
            <a href="javascript:;" class="tab-this">障害信息</a>
            <a href="javascript:;">改修内容</a>
            <a href="javascript:;">改修确认</a>
        </span>
    </div>
    <div class="user-mine">
        <div class="layui-form layui-form-pane mine-view" style="display:block;">
            <form action="@Url.Action("BugInfo","Project")" method="post">
                @Html.AntiForgeryToken()
                <input type="hidden" name="Id" value="@Model.Id" />
                <input type="hidden" id="Status" name="Status" value="@Model.Status" />
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">障害番号</label>
                        <div class="layui-input-block">
                            <input id="No" name="No" class="layui-input" readonly="readonly" value="@Model.No" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">机能ID</label>
                        <div class="layui-input-block">
                            <input id="PageId" name="PageId" class="layui-input" required lay-verify="required" value="@Model.PageId" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">机能名</label>
                        <div class="layui-input-block">
                            <input id="PageName" name="PageName" class="layui-input" required lay-verify="required" value="@Model.PageName" />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">操作内容</label>
                    <div class="layui-input-block">
                        <input id="Operation" name="Operation" class="layui-input" required lay-verify="required" value="@Model.Operation" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">发生现象</label>
                    <div class="layui-input-block">
                        <input id="Happening" name="Happening" class="layui-input" required lay-verify="required" value="@Model.Happening" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">本来式样</label>
                    <div class="layui-input-block">
                        <input id="Original" name="Original" class="layui-input" required lay-verify="required" value="@Model.Original" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">发生日</label>
                        <div class="layui-input-block">
                            <input id="HappenDay" name="HappenDay" class="layui-input autoIn" value="@Model.HappenDay" readonly="readonly" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">发行者</label>
                        <div class="layui-input-block">
                            <input id="IssuerName" name="IssuerName" class="layui-input autoIn" readonly="readonly" value="@Model.IssuerName" />
                            <input id="Issuer" name="Issuer" type="hidden" class="autoIn" value="@Model.Issuer" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">优先级</label>
                        <div class="layui-input-block" style="width:180px">
                            <select id="Priority" name="Priority">
                                <option value="0">普通</option>
                                <option value="1">至急</option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">预定完了日</label>
                        <div class="layui-input-block">
                            <input id="BookEndDate" name="BookEndDate" class="layui-input laydate" value="@Model.BookEndDate"
                                   required lay-verify="required" readonly="readonly" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">确认日</label>
                        <div class="layui-input-block">
                            <input id="ConfirmDay" name="ConfirmDay" class="layui-input" readonly="readonly" value="@Model.ConfirmDay" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">确认者</label>
                        <div class="layui-input-block">
                            <input id="ConfirmUser" name="ConfirmUserName" class="layui-input" readonly="readonly" value="@Model.ConfirmUserName" />
                            <input id="ConfirmUser" name="ConfirmUser" type="hidden" value="@Model.ConfirmUser" />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">附件</label>
                    <div class="layui-input-block">
                        <input id="Annex" name="Annex" class="layui-input" value="@Model.Annex" />
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label for="Info" class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea id="TestRemark" name="Remark" autocomplete="off" class="layui-textarea">@Model.Remark</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-btn-container">
                        @if (string.IsNullOrEmpty(Model.Status) || (Model.Status == "0" && ViewBag.Issuer))
                        {
                            <button id="BugAdd" class="layui-btn layui-btn-normal" lay-submit lay-filter="addBug">信息提交</button>
                        }
                        else if (Model.Status == "1" && ViewBag.Issuer)
                        {
                            <button id="BugConfirm" class="layui-btn layui-btn-normal" lay-submit lay-filter="addBug">障害确认</button>
                            <button id="BugRevise" class="layui-btn layui-btn-normal" lay-submit lay-filter="addBug">修正不足</button>
                        }
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-form layui-form-pane mine-view">
            <form action="@Url.Action("BugRevise","Project")" method="post">
                @Html.AntiForgeryToken()
                <input type="hidden" name="Id" value="@Model.Id" />
                <input type="hidden" name="No" value="@Model.No" />
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:120px">现象区分</label>
                        <div class="layui-input-block" style="margin-left:120px">
                            <select id="SceneKind" name="SceneKind" required lay-verify="required">
                                <option value="">请选择</option>
                                @foreach (var item in Model.SceneKindDic.Keys)
                                {
                                    <option value="@item">@Model.SceneKindDic[item]</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:120px">原因区分(小)</label>
                        <div class="layui-input-block" style="margin-left:120px">
                            <select id="ReasonSmall" name="ReasonSmall" required lay-verify="required">
                                <option value="">请选择</option>
                                @foreach (var item in Model.ReasonSmallDic.Keys)
                                {
                                    <option value="@item">@Model.ReasonSmallDic[item]</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:120px">障害区分</label>
                        <div class="layui-input-block" style="margin-left:120px">
                            <select id="BugKind" name="BugKind" required lay-verify="required">
                                <option value="">请选择</option>
                                @foreach (var item in Model.BugKindDic.Keys)
                                {
                                    <option value="@item">@Model.BugKindDic[item]</option>
                                }
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:120px">修正者</label>
                        <div class="layui-input-block" style="margin-left:120px;width:212px;">
                            <input id="ReviseUserName" name="ReviseUserName" class="layui-input autoIn" readonly="readonly" value="@Model.ReviseUserName" />
                            <input id="ReviseUser" name="ReviseUser" class="autoIn" type="hidden" value="@Model.ReviseUser" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:120px">修正日</label>
                        <div class="layui-input-block" style="margin-left:120px;width:212px;">
                            <input id="ReviseDay" name="ReviseDay" class="layui-input autoIn" readonly="readonly"
                                   value="@Model.ReviseDay" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width:120px">原因区分(大)</label>
                        <div class="layui-input-block" style="margin-left:120px">
                            <select id="ReasonBig" name="ReasonBig" required lay-verify="required">
                                <option value="">请选择</option>
                                @foreach (var item in Model.ReasonBigDic.Keys)
                                {
                                    <option value="@item">@Model.ReasonBigDic[item]</option>
                                }
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" style="width:120px">修正文件</label>
                    <div class="layui-input-block" style="margin-left:120px;width:908px;">
                        <input id="ReviseFile" name="ReviseFile" required lay-verify="required" class="layui-input" value="@Model.ReviseFile" />
                    </div>
                </div>
                <div class="layui-form-item layui-form-text" style="width:1028px;">
                    <label class="layui-form-label">修正后</label>
                    <div class="layui-input-block">
                        <textarea id="ReviseAft" name="ReviseAft" required lay-verify="required" class="layui-textarea">@Model.ReviseAft</textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text" style="width:1028px;">
                    <label class="layui-form-label">修正前</label>
                    <div class="layui-input-block">
                        <textarea id="ReviseBef" name="ReviseBef" required lay-verify="required" class="layui-textarea">@Model.ReviseBef</textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text" style="width:1028px;">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea id="DevelopRemark" name="Remark" autocomplete="off" class="layui-textarea">@Model.Remark</textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    @if (Model.Status=="0" || Model.Status == "1" || Model.Status=="2")
                    {
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="addBug">信息提交</button>
                    }
                </div>
            </form>
        </div>


        <div class="layui-form layui-form-pane mine-view">
            <form action="@Url.Action("BugAccept","Project")" method="post">
                @Html.AntiForgeryToken()
                @{
                    var chm = Model.IsUnfold == "1" ? "checked" : "";
                    var chw = Model.IsUnfold != "1" ? "checked" : "";
                    var dis = ViewBag.IsManager || IsAdmin?  "": "disabled";
                }
                <input type="hidden" name="Id" value="@Model.Id" />
                <input type="hidden" name="No" value="@Model.No" />
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">承认者</label>
                        <div class="layui-input-block">
                            <input id="AcceptUserName" name="AcceptUserName" class="layui-input autoIn" readonly="readonly" value="@Model.AcceptUserName" />
                            <input id="AcceptUser" name="AcceptUser" class="autoIn" type="hidden" value="@Model.AcceptUser" />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">展开要否</label>
                        <div class="layui-input-block">
                            <input type="radio" name="IsUnfold" value="1" title="是" @chm  @dis />
                            <input type="radio" name="IsUnfold" value="0" title="否" @chw  @dis />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">展开番号</label>
                        <div class="layui-input-block">
                            <input id="UnfoldNo" name="UnfoldNo" class="layui-input" value="@Model.UnfoldNo" @dis />
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    @if ((ViewBag.IsManager || IsAdmin) && Model.Status=="3")
                    {
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="addBug">信息提交</button>
                    }
                </div>
            </form>
        </div>
    </div>
</div>
@section scripts{
    <script>
        layui.use(['laydate', 'jquery', 'form', 'element'], function () {
            var laydate = layui.laydate;
            var $ = layui.jquery;
            var form = layui.form;
            laydate.render({
                elem: '.laydate'
                , type: 'date'
                , theme: '#558AC0'
                , format: 'yyyy/MM/dd'
                , trigger: 'click'
            });

            var uid = layui.data("user").user.uid;
            var username = layui.data("user").user.username;
            $(".autoIn").each(function () {
                if ($(this).val() == "") {
                    if ($(this).attr("id").indexOf("Name") > 0) {
                        $(this).val(username);
                    } else if ($(this).attr("id").indexOf("Day") > 0) {
                        $(this).val('@DateTime.Now.ToString("yyyy/MM/dd")');
                    } else {
                        $(this).val(uid);
                    }

                }
            });          

            $("#SceneKind").val("@Model.SceneKind");
            $("#ReasonSmall").val("@Model.ReasonSmall");
            $("#BugKind").val("@Model.BugKind");
            $("#ReasonBig").val("@Model.ReasonBig");
            form.render();

            $("#tabs").find("a").click(function () {
                index = $(this).index();
                if ('@Model.Status'=='' && index != 0) {
                    layer.msg('请先完成障害录入', { icon: 7 });
                    return;
                }
                if ('@Model.Status' !='3' && index == 2) {
                    layer.msg('请先确认障害已经修正', { icon: 7 });
                    return;
                }
                $("#tabs").find("a").removeClass("tab-this");
                $(this).addClass("tab-this");
                $('.mine-view').hide();
                $('.mine-view').eq(index).show();
            });


            $("#PageId").click(function (){                    
                layer.open({
                    type: 2,
                    title: '机能选择',
                    maxmin: false,
                    area: ['480px', '600px'],
                    content: '@Url.Action("Pages", "Project")',
                    success: function (layero, index) {
                        var iframe = window['layui-layer-iframe' + index];
                        iframe.child('@Model.Id');
                    }
                });
            });

            $("#BugConfirm").click(function () {
                $("#Status").val("3");
            });

            $("#BugRevise").click(function () {
                $("#Status").val("2");
            });

            form.on('submit(addBug)', function (data) {
                var action = $(data.form).attr('action'); 
                $.post(action, data.field, function (res) {
                    if (res.status==1) {
                        layer.msg(res.msg, { icon: 2 });
                    } else {
                        layer.msg(res.msg, { icon: 1,time:1000 }, function (index) {
                            layer.close(index);  
                            redirect('Project', 'Bug', '@Model.Id');
                        });
                    }
                }, 'json');
                return false;
            });
        })
    </script>
}